import 'package:expensy_flutter/_inner_packages.dart';

class StringHelper {
  static double extractDoubleOrZero(String text) {
    double result;
    try {
      result = double.parse(text.replaceAll(new RegExp(r'[^0-9\.]'), ''));
    } catch (e) {
      result = 0;
    }
    return result;
  }

  static double extractIntegerOrZero(String text) {
    double result;
    try {
      result = double.parse(text.replaceAll(new RegExp(r'[^0-9]'), ''));
    } catch (e) {
      result = 0;
    }
    return result;
  }

  static String getRandomString(int len) {
    var random = Random.secure();
    var values = List<int>.generate(len, (i) => random.nextInt(255));
    return base64UrlEncode(values);
  }
}
